package com.ruoyi.luban.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.luban.domain.PKnowledge;
import com.ruoyi.luban.mapper.PKnowledgeMapper;
import com.ruoyi.luban.service.IPKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 维修知识Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-23
 */
@Service
public class PKnowledgeServiceImpl implements IPKnowledgeService
{
    @Autowired
    private PKnowledgeMapper pKnowledgeMapper;

    /**
     * 查询维修知识
     * 
     * @param id 维修知识主键
     * @return 维修知识
     */
    @Override
    public PKnowledge selectPKnowledgeById(Long id)
    {
        PKnowledge pKnowledge = pKnowledgeMapper.selectPKnowledgeById(id);
        if(pKnowledge != null){
            Long aLong = pKnowledge.getViews() + 1;
            pKnowledge.setViews(aLong);
            pKnowledgeMapper.updatePKnowledge(pKnowledge);
        }
        return pKnowledge;
    }

    /**
     * 查询维修知识列表
     * 
     * @param pKnowledge 维修知识
     * @return 维修知识
     */
    @Override
    public List<PKnowledge> selectPKnowledgeList(PKnowledge pKnowledge)
    {
        return pKnowledgeMapper.selectPKnowledgeList(pKnowledge);
    }

    /**
     * 新增维修知识
     * 
     * @param pKnowledge 维修知识
     * @return 结果
     */
    @Override
    public int insertPKnowledge(PKnowledge pKnowledge)
    {
        pKnowledge.setCreateTime(DateUtils.getNowDate());
        return pKnowledgeMapper.insertPKnowledge(pKnowledge);
    }

    /**
     * 修改维修知识
     * 
     * @param pKnowledge 维修知识
     * @return 结果
     */
    @Override
    public int updatePKnowledge(PKnowledge pKnowledge)
    {
        pKnowledge.setUpdateTime(DateUtils.getNowDate());
        return pKnowledgeMapper.updatePKnowledge(pKnowledge);
    }

    /**
     * 批量删除维修知识
     * 
     * @param ids 需要删除的维修知识主键
     * @return 结果
     */
    @Override
    public int deletePKnowledgeByIds(Long[] ids)
    {
        return pKnowledgeMapper.deletePKnowledgeByIds(ids);
    }

    /**
     * 删除维修知识信息
     * 
     * @param id 维修知识主键
     * @return 结果
     */
    @Override
    public int deletePKnowledgeById(Long id)
    {
        return pKnowledgeMapper.deletePKnowledgeById(id);
    }
}
